import ajaxOnePsnData from "./ajaxOnePsnData";
import {deepClone} from 'nc-lightapp-front';

export default function getOnePsnData(pk_psnjob, callback) {
    const {orgVal, func_type} = this.props;

    let postData = {
        pk_org: orgVal.refpk,
        func_type,
        pk_psnjob
    };

    return ajaxOnePsnData(postData)
        .then((res) => {
            if (res.success) {
                let meta = this.props.meta.getMeta();
                res.data.displayArea = [];
                res.data.areaCodeList.forEach(item => {
                    meta[item] = res.data.allArea[item];
                    if (meta[item].moduletype === 'table') {
                        meta['gridrelation'][item] = {
                            destBrowseAreaCode: null,
                            destEditAreaCode: null,
                            srcAreaCode: item,
                            tabRelation: [item]
                        };
                    }
                    res.data.displayArea.push(meta[item]);
                });

                meta.hi_psnjob_history = deepClone(res.data.allArea.hi_psnjob);

                this.props.meta.setMeta(meta);
                callback && callback(res.data);
            }
        });
}
